package com.lz.football.module.activity.CdKey
{
	import com.common.stdlib.StringUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.lz.football.module.activity.ICDKeyAwardView;
	
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.Alert;
	import lz.controls.core.TitleWindow;

	/**
	 *激活码兑换礼品 
	 * @author lake
	 * 
	 */	
	public class CDKeyAwardView extends TitleWindow implements ICDKeyAwardView
	{
		/**
		 * 领奖
		 */		
		private var getBtn 	:SimpleButton;
		/**
		 *输入框 
		 */		
		private var txtInput	:TextField;
		
		public function CDKeyAwardView()
		{
			super();
		}
		/**
		 *初始化 
		 * 
		 */
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.football.act.skin.cdkeyview");
			_symbolSkin.cacheAsBitmap = true;
			getBtn = _symbolSkin.getBtn;
			txtInput = _symbolSkin.txtInput;
			txtInput.text = "";
			GlobalDef.GameStage.focus = txtInput;
			//getBtn.mouseEnabled = false;
			//初始化宽高
			width = _symbolSkin.width;
			height = _symbolSkin.height;
			//初始化UI界面控件
			windowBg = _symbolSkin.windowBg;//背景框
			windowBg.mouseChildren = false;
			//设置可拖动
			dragEnabled = true;
			this.addChild(_symbolSkin);
			closeBtn = Reflection.createInstance("com.lz.commonUI.closeBtn");
			this.addChild(closeBtn);
			closeBtn.x = 409;
			closeBtn.y = 32;
			//设置关闭按钮
			setCloseBtn(closeBtn);
			//add event
			addEvtListener();
		}
		/**
		 *注册事件 
		 * 
		 */
		public function addEvtListener():void
		{
			getBtn.addEventListener(MouseEvent.CLICK,getClickH);
		}
		/**
		 * onCloseHandler
		 * @param e
		 * 
		 */		
		override protected function onCloseHandler(e :MouseEvent):void
		{
			this.dispatchEvent(new ModuleEvent(ModuleEvent.REMOVE_MODULE));
		}
		/**
		 *领取奖励 
		 * @param e
		 * 
		 */		
		private function getClickH(e :MouseEvent):void
		{
			var keyStr :String = txtInput.text;
			keyStr = keyStr.replace(/\ /g,"");
			keyStr = StringUtil.trim(keyStr);
			if(keyStr == null || keyStr == "")
			{
				Alert.showErrorTip("请输入激活码!");
				return ;
			}
			GlobalDef.GameStage.focus = null;
			getBtn.mouseEnabled = false;
			this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_CDKEY_AWARD,{cdkey:keyStr}));
		}
		/**
		 *领取返回 
		 * @param obj
		 * 
		 */		
		public function getAwardRes(obj:Object):void
		{
			getBtn.mouseEnabled = true;
		}
		/**
		 *删除事件 
		 * 
		 */
		public function removeEvtListener():void
		{
			closeBtn.removeEventListener(MouseEvent.CLICK,onCloseHandler);
			getBtn.removeEventListener(MouseEvent.CLICK,getClickH);
		}
		/**
		 *销毁 
		 * 
		 */
		public function destroyView():void
		{
			removeEvtListener();
			if(this.parent)
			{
				this.parent.removeChild(this);
			}
			_symbolSkin = null;
			closeBtn = null;
			GlobalDef.GameStage.focus = null;
		}
		/**
		 *显示tab类型 
		 * @param $obj
		 * 
		 */
		public function showType($obj:Object):void
		{
		}
	}
}